package com.zx.crowdfunding.api;

import java.util.concurrent.TimeUnit;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.zx.crowdfunding.util.ResultEntity;

/**
 * Redis数据远程服务接口
 * 
 * @author 郑雪
 * @date 2021-12-29
 */
// @FeignClient注解表示当前接口和一个Provider对应，注解中value属性指定要调用的Provider的微服务名称
@FeignClient("crowdfunding-redis")
public interface RedisRemoteService {

	/**
	 * 设置Redis键值对，并且不带超时时间
	 * @param key 	要存入redis的键
	 * @param value 要存入redis的值
	 * @return ResultEntity对象
	 */
	@RequestMapping("/set/redis/key/value/remote")
	ResultEntity<String> setRedisKeyValueRemote(
				@RequestParam("key") String key, 
				@RequestParam("value") String value
			);
	
	/**
	 * 设置Redis键值对，并且带超时时间
	 * @param key 		要存入redis的键
	 * @param value 	要存入redis的值
	 * @param timeout 	超时时间
	 * @param timeUnit 	时间单位
	 * @return ResultEntity对象
	 */
	@RequestMapping("/set/redis/key/value/remote/with/timeout")
	ResultEntity<String> setRedisKeyValueRemoteWithTimeout(
				@RequestParam("key") String key, 
				@RequestParam("value") String value, 
				@RequestParam("timeout") long timeout, 
				@RequestParam("timeUnit") TimeUnit timeUnit
			);
	
	/**
	 * 通过键获取Redis的字符串值
	 * @param key redis的键
	 * @return ResultEntity对象
	 */
	@RequestMapping("/get/redis/string/value/by/key/remote")
	ResultEntity<String> getRedisStringValueByKeyRemote(@RequestParam("key") String key);
	
	/**
	 * 删除Redis的值
	 * @param key redis的键
	 * @return ResultEntity对象
	 */
	@RequestMapping("/remove/redis/key/remote")
	ResultEntity<String> removeRedisKeyRemote(@RequestParam("key") String key);
}
